package com.lac.component.lock;

/**
 * @author xiaokuixiao
 * date2025/7/29 15:10
 */
import java.util.concurrent.locks.ReentrantLock;

public class ReentrantLockDemo {
    private final ReentrantLock lock = new ReentrantLock();

    public void performTask() {
        lock.lock();  // 获取锁
        try {
            // 临界区代码（线程安全操作）
            System.out.println(Thread.currentThread().getName() + " 持有锁");
        } finally {
            lock.unlock();  // 必须确保释放锁
            System.out.println(Thread.currentThread().getName() + " 释放锁");
        }
    }
}